//
//  textdemoViewController.m
//  wuyeviewcon
//
//  Created by dsdf on 16/1/22.
//  Copyright © 2016年 joey. All rights reserved.
//

#import "textdemoViewController.h"
#import "TableHeadView.h"

#import "MyHomeTableViewCell.h"
#import "CHDDropDownMenu.h"

@interface textdemoViewController ()

@end

@implementation textdemoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    UIButton *button=[[UIButton alloc]init];
    button.frame=CGRectMake(0, 0, 375, 64);
    button.backgroundColor=[UIColor colorWithRed: 230/255.0 green:55/255.0 blue:55/255.0 alpha:1.0];
    [self.view addSubview:button];
    
    
    UILabel *labletext=[[UILabel alloc]init];
    labletext.frame=CGRectMake(155, 34, 66, 14);
    labletext.text=@"物业账单";
    labletext.adjustsFontSizeToFitWidth=YES;
    labletext.textColor=[UIColor whiteColor] ;
    [self.view addSubview:labletext];
    
    
    
    
    
    
    
    UIButton *button1=[[UIButton alloc]init ];//]WithFrame:CGRectMake(50, 50, 20, 20)];
    button1.frame=CGRectMake(22, 35, 20, 20);
    [button1 setBackgroundImage:[UIImage imageNamed:@"return@2x.png"] forState:UIControlStateNormal];
    [button1 addTarget:self action:@selector(fanhui:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button1];
    
    
    
//    UIButton *button2=[[UIButton alloc]init];
//    button2.frame=CGRectMake(0, 64, 375, 237);
//    button2.backgroundColor=[UIColor whiteColor];
//    [self.view addSubview:button2];
//    
//    
//
//    
//    UISegmentedControl *maseg=[[UISegmentedControl alloc]init];
//    [maseg setWidth:100 forSegmentAtIndex:0];
//    maseg.segmentedControlStyle=UISegmentedControlStyleBar;
//    
//
 /*  
  
  
  // Control in navigation bar
  self.segmentedControl = [[NYSegmentedControl alloc] initWithItems:@[@"Light", @"Dark"]];
  [self.segmentedControl addTarget:self action:@selector(segmentSelected) forControlEvents:UIControlEventValueChanged];
  self.segmentedControl.titleFont = [UIFont fontWithName:@"AvenirNext-Medium" size:14.0f];
  self.segmentedControl.titleTextColor = [UIColor colorWithWhite:0.5f alpha:1.0f];
  self.segmentedControl.selectedTitleFont = [UIFont fontWithName:@"AvenirNext-DemiBold" size:14.0f];
  self.segmentedControl.selectedTitleTextColor = [UIColor whiteColor];
  self.segmentedControl.borderWidth = 1.0f;
  self.segmentedControl.borderColor = [UIColor colorWithWhite:0.15f alpha:1.0f];
  self.segmentedControl.drawsGradientBackground = YES;
  self.segmentedControl.segmentIndicatorInset = 2.0f;
  self.segmentedControl.segmentIndicatorGradientTopColor = [UIColor colorWithRed:0.30 green:0.50 blue:0.88f alpha:1.0f];
  self.segmentedControl.segmentIndicatorGradientBottomColor = [UIColor colorWithRed:0.20 green:0.35 blue:0.75f alpha:1.0f];
  self.segmentedControl.drawsSegmentIndicatorGradientBackground = YES;
  self.segmentedControl.segmentIndicatorBorderWidth = 0.0f;
  self.segmentedControl.selectedSegmentIndex = 0;
  [self.segmentedControl sizeToFit];
  self.navigationItem.titleView = self.segmentedControl;
  
  
  */
    
    NSArray *arry=[[NSArray alloc]initWithObjects:@"账单",@"欠费", nil];
    UISegmentedControl *sege=[[UISegmentedControl alloc]initWithItems:arry];
    sege.frame=CGRectMake(12,156,352,35);
    sege.selectedSegmentIndex=0;
    sege.tintColor=[UIColor redColor];
    sege.backgroundColor=[UIColor whiteColor];
    //sege.momentary=YES;
    sege.segmentedControlStyle=UISearchBarStyleDefault;
    sege.layer.masksToBounds=YES;
    //[sege addTarget:selfaction:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
    [sege addTarget:self action:@selector(controlPressed:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:sege];

    
    
    

    
    
    
    _tableview.separatorStyle=UITableViewCellSeparatorStyleNone;
    _tableview.delegate=self;
    _tableview.dataSource=self;
    _tableview.rowHeight = 94;
    

    
//    
//    UIButton *checkbox11 = [UIButton buttonWithType:UIButtonTypeCustom];
//    
//    checkbox11.frame=CGRectMake(12,156,176,35);
//    
//    [checkbox11 setImage:[UIImage imageNamed:@"账单点击时状态@2x.png"] forState:UIControlStateNormal];
//    [checkbox11 setImage:[UIImage imageNamed:@"账单未点击状态@2x.png"] forState:UIControlStateSelected];
//    [checkbox11 addTarget:self action:@selector(weimian:) forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:checkbox11];
//    
//    
//    UIButton *checkbox12 = [UIButton buttonWithType:UIButtonTypeCustom];
//    
//    checkbox12.frame=CGRectMake(188,156,176,35);
//    
//    [checkbox12 setImage:[UIImage imageNamed:@"欠费未点击状态@2x.png"] forState:UIControlStateNormal];
//    [checkbox12 setImage:[UIImage imageNamed:@"欠费点击状态@2x.png"] forState:UIControlStateSelected];
//    [checkbox12 addTarget:self action:@selector(weimian2:) forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:checkbox12];
//    
//    
//
    
    //列表展示的模型
    NSMutableArray *arr = [NSMutableArray array];
    for (int i =0; i<1; i++) {
        NSMutableArray *temp = [NSMutableArray array];
        NSInteger row = (i+1)*3;
        for (int j =0; j<row; j++) {
            chdModel *model = [[chdModel alloc] init];
            model.text = [NSString stringWithFormat:@"幸福小区%@栋%@单元",@(i),@(j)];
            if (( i == 2 && j >= 2 && j < 4) || ( i == 2 && j == 7)) {
                model.isSub = YES;
            }
            
            [temp addObject:model];
        }
        [arr addObject:temp];
    }
    
    //上边按钮展示的模型,此模型对text赋值即可.
    NSMutableArray *ShowArr = [NSMutableArray array];
    for (int i =0; i<1; i++) {
        NSMutableArray *temp = [NSMutableArray array];
        NSInteger row = (i+1)*3;
        for (int j =0; j<row; j++) {
            chdModel *model = [[chdModel alloc] init];
            model.text = [NSString stringWithFormat:@"幸福小区%@栋%@单元",@(i),@(j)];
            [temp addObject:model];
        }
        [ShowArr addObject:temp];
    }

    


    [[CHDDropDownMenu alloc] initWithFrame:CGRectMake(123,87,134,14) showOnView:self.view AllDataArr:arr showArr:ShowArr];
    
    
            NSMutableArray *ar = [NSMutableArray array];
            for (int i =0; i<1; i++) {
                NSMutableArray *tem = [NSMutableArray array];
                NSInteger roll = 12;
                for (int j =0; j<roll; j++) {
                    chdModel *mode = [[chdModel alloc] init];
                    mode.text = [NSString stringWithFormat:@"2015-%@",@(j)];
                    if (( i == 2 && j >= 2 && j < 4) || ( i == 2 && j == 7)) {
                        mode.isSub = YES;
                    }
    
                    [tem addObject:mode];
                }
                [ar addObject:tem];
            }
    
            //上边按钮展示的模型,此模型对text赋值即可.
            NSMutableArray *ShowAr= [NSMutableArray array];
            for (int i =0; i<1; i++) {
                NSMutableArray *te = [NSMutableArray array];
                NSInteger roll= 12;
                for (int j =0; j<roll; j++) {
                    chdModel *mo = [[chdModel alloc] init];
                    mo.text = [NSString stringWithFormat:@"2015-9"];
                    [te addObject:mo];
                }
                [ShowAr addObject:te];
            }
    
    
    
    
    
    
    
    
    [[CHDDropDownMenu alloc] initWithFrame:CGRectMake(87,209,62,30) showOnView:self.view AllDataArr:ar showArr:ShowAr];
    
    
    
    [[CHDDropDownMenu alloc] initWithFrame:CGRectMake(214,210,62,30) showOnView:self.view AllDataArr:ar showArr:ShowAr];
    
//    [[CHDDropDownMenu alloc] initWithFrame:CGRectMake(214,210,62,30) showOnView:self.view AllDataArr:arr1 showArr:ShowArr1];
    
    

    
}

- (IBAction)fanhui:(id)sender {
    [self dismissModalViewControllerAnimated:YES];
}


- (IBAction)doit:(id)sender {



}

- (IBAction)weimian:(id)sender {
    
//    if (sender.tag=10) {
//        
//    }
//
    
//    _view1.alpha=0;
//    _view2.alpha=1;
    
    
    _view2.alpha=0;
    _view1.alpha=1;
    

    
}



- (IBAction)weimian2:(id)sender {
    
    //    if (sender.tag=10) {
    //
    //    }
    //
    _view1.alpha=0;
    _view2.alpha=1;
    
    
}


-(void)controlPressed:(id)sender{
    
    
    
    UISegmentedControl *control = (UISegmentedControl *)sender;
    
    
    
    int x = control.selectedSegmentIndex;
    
    switch (x) {
        case 0:
            NSLog(@"1");
            
            _view1.alpha=0;
            _view2.alpha=1;
            break;
            
        default:
            NSLog(@"2");
            //
            _view1.alpha=1;
            _view2.alpha=0;
            
            break;
    }
    
    
    
}







- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (isFlag[section]) {
        return 1;
    }else{
        return 0;
    }
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString * str = @"cell1";
    MyHomeTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:str];
    if (!cell) {
        cell=[[[NSBundle mainBundle]loadNibNamed:@"MyHomeTableViewCell" owner:nil options:nil]objectAtIndex:1];
    }
    return cell;
}


//表头高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 70;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 6;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    TableHeadView * headView=[[NSBundle mainBundle] loadNibNamed:@"TableHeadView" owner:nil options:nil][0];
    headView.tableHeadBtn.tag = 10+section;
    [headView.tableHeadBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    return headView;
    
}




//区头的方法
- (void)btnClick:(UIButton *)sender {
    NSLog(@"%d",sender.tag-10);
    NSInteger section =sender.tag-10;
    isFlag[section]=!isFlag[section];
    NSIndexSet *set =[NSIndexSet indexSetWithIndex:section];
    [_tableview reloadSections:set withRowAnimation:UITableViewRowAnimationFade];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
